﻿Imports System.IO
Imports Lucene.Net.Analysis
Imports Lucene.Net.Analysis.Standard
Imports Lucene.Net.Analysis.Snowball
Imports Aricie.DNN.Modules.LuceneSearch.Common.Constants

Namespace Aricie.DNN.Modules.LuceneSearch.Business

    ''' <summary>
    ''' Accent Filtered SnowBall Analyzer
    ''' </summary>
    ''' <remarks></remarks>
    Public Class SnowballAccentAnalyzer
        Inherits Analyzer

#Region "Private members"

        Private name As String
        Private stopSet As HashSet(Of String)

#End Region

#Region "ctor"

        Public Sub New(ByVal name As String)
            Me.name = name
        End Sub

        Public Sub New(ByVal name As String, ByVal stopWords As String())
            Me.New(name)
            Me.stopSet = SpecificVersionLuceneProvider.Instance().MakeStopSet(stopWords)
        End Sub

#End Region

#Region "Overrides"

        Public Overrides Function TokenStream(ByVal fieldName As String, ByVal reader As TextReader) As TokenStream
            Dim stream As TokenStream = New StandardTokenizer(LuceneCurrentVersion, reader)
            stream = New StandardFilter(stream)
            stream = New LowerCaseFilter(stream)
            If (Not Me.stopSet Is Nothing) Then
                stream = SpecificVersionLuceneProvider.Instance().GetStopFilter(True, stream, Me.stopSet, True)
            End If
            stream = New ASCIIFoldingFilter(stream)
            Return New SnowballFilter(stream, Me.name)
        End Function

#End Region

    End Class

End Namespace